import Order from '../../../Common/Order/';
import {cbs} from '../../../../config/settings.js';
import {mapGetters} from 'vuex';

module.exports = {
  name: 'Empty',
  data(){
  	return{
        tableData: [],
        total:1,
        page:1,
        size:3,
        isEmptyBarry: true
  	}
  },
  components:{Order},
  methods: {
      /**
       * 获取空桶订单
       */
      getOrders(){
          let data = this.$$formData({
              pageNum: this.page,
              size: this.size
          })

          this.$$api_order_emptyBarrel(data, res => {
              if(res.event === 0) {
                  this.tableData = res.obj;
                  this.total = res.maxCount;
                  this.$store.dispatch('update_empty_barrel_orders', this.total);
              }else {
                  cbs.submitError.call(this, `获取待确认空桶订单信息失败，${res.msg}`);
              }
          })
      },
      /**
       * 改变当前页数
       */
      handleCurrentChange(v) {
        this.page = v;
        this.getOrders();
      },
      /**
       * 接收订单
       */
      onReceiveOrder(id) {
          let data = this.$$formData({
              orderWaterStoreId: id
          })

          this.$$api_order_confirmBarrel(data, res => {
              if(res.event === 0) {
                  this.getOrders();
              }else {
                  cbs.submitError.call(this, `接收失败，${res.msg}，请重新接收`);
              }
          })
      },
      /**
       * 拒绝订单
       */
      onRejectOrder(id) {
          let data = this.$$formData({
              orderWaterStoreId: id
          })

          this.$$api_order_RefuseBarrel(data, res => {
              if(res.event === 0) {
                  this.getOrders();
              }else {
                  cbs.submitError.call(this, `拒绝失败，${res.msg}，请重新提交`);
              }
          })
      }
  },
  created() {
      this.getOrders();
  },
  computed: mapGetters({
      deposite: 'getDepositeOrders'
  })
}